//
//  zhutiTableViewCell2.m
//  BAOASystem
//
//  Created by michael on 2018/5/22.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "qiyexqViewController.h"
#import "qiyecaigouViewController.h"
#import "caigouxqViewController.h"
#import "zhutiTableViewCell2.h"
#import "bendititleTableViewCell.h"
@implementation zhutiTableViewCell2
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleView = [[TOPageTitleView alloc] init];
        _titleView.miniGap = 10;
                  self.titleView.titles = self.titles;
_titleView.titleColor =[UIColor colorWithHexString:@"0a62ea"];
        _titleView.  selectedTitleColor =[UIColor colorWithHexString:@"0a62ea"];
 self.titleView.titleViewDelegate = self;
    self.titleView.indicatorHeight = 2.0;
    self.titleView. selectedTextFont= [UIFont systemFontOfSize: 16.0];

    self.titleView.textFont = [UIFont systemFontOfSize: 16.0];
   _titleView. indicatorColor =[UIColor colorWithHexString:@"0a62ea"];
    self.titleView.frame = CGRectMake(0, 0, KScreenWidth/2, 39);
    self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    [self.contentView addSubview:self.titleView];
    UIView *bomview = [[UIView alloc]initWithFrame:CGRectMake(0, _titleView.bottom, KScreenWidth, 1)];
bomview.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    [self.contentView addSubview:bomview];
  self.tableview.frame = CGRectMake(0, 40, KScreenWidth,120);

 [self.contentView addSubview:self.tableview];
 
     UIView *bomview2 = [[UIView alloc]initWithFrame:CGRectMake(0, _tableview.bottom, KScreenWidth, 10)];
bomview2.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    [self.contentView addSubview:bomview2];
    }
    return self;
}
-(UITableView *)tableview{
if (!_tableview) {
  _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, KScreenWidth,120) style:UITableViewStylePlain];
  _tableview.dataSource = self;
  _tableview.delegate = self;
  _tableview.backgroundColor = [UIColor whiteColor];
  _tableview.bounces = NO;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return _tableview;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _array.count;

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cellbendititlepic";

    bendititleTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

if (cell==nil) {
        cell=[[bendititleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    
 NSDictionary *dic = self.array[indexPath.row];
    cell.dic = dic;
    return cell;
    }
-(void)setPurchasearray:(NSArray *)purchasearray{
_purchasearray = purchasearray;
_array = _purchasearray;
[_tableview reloadData];
}
-(void)setSupplyarray:(NSArray *)supplyarray{
_supplyarray = supplyarray;
}
- (NSMutableArray<TOPageItem *> *)titles{
    if (!_titles) {
        _titles = [NSMutableArray arrayWithArray:@[
                                                   [TOPageItem itemWithTitle:NSLocalizedString(@"商家-采购商", nil)],
                                                   [TOPageItem itemWithTitle:NSLocalizedString(@"商家-供应商", nil)],
                                                   
                                                   ]];
    }
    return _titles;
}
- (void)pageTitleView:(TOPageTitleView *)pageTitleView didSelecteIndex:(NSInteger)index oldIndex:(NSInteger)oldIindex{
if (index ==0) {
_array = _purchasearray;
_type = @"0";
[_tableview reloadData];
}if (index ==1) {
_array = _supplyarray;
_type = @"1";
[_tableview reloadData];
}

    NSLog(@"%ld",(long)index);


}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 if ([_type isEqualToString:@"0"]) {
 NSDictionary *dic = _array[indexPath.row];
 qiyecaigouViewController *vc = [[qiyecaigouViewController alloc]init];
 vc.pdid = dic[@"id"];
 vc.hidesBottomBarWhenPushed = YES;
 [self.ViewController.navigationController pushViewController:vc animated:YES];

 }else{
 NSDictionary *dic = _array[indexPath.row];
 qiyexqViewController *vc = [[qiyexqViewController alloc]init];
 vc.pdid = dic[@"id"];
 vc.hidesBottomBarWhenPushed = YES;
 [self.ViewController.navigationController pushViewController:vc animated:YES];

 }

 
 }
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
